#include "kernel_operator.h"
using namespace AscendC;

// #define SCA
// #define PRINTF

class HeavisideSca {
   public:
    __aicore__ inline HeavisideSca() {} 
    __aicore__ inline void Init(GM_ADDR input, GM_ADDR values, GM_ADDR out, uint32_t inputSize, uint32_t valueSize, TPipe* pipeIn) {
        printf("in sca init\n");

        this->coreNum = GetBlockNum();
        this->coreIndex = GetBlockIdx();
        this->pipe = pipeIn;
        this->inputSize = inputSize;
        this->valueSize = valueSize;

		inputGm.SetGlobalBuffer((__gm__ DTYPE_INPUT*)input, inputSize * sizeof(DTYPE_INPUT));
        valuesGm.SetGlobalBuffer((__gm__ DTYPE_INPUT*)values, valueSize * sizeof(DTYPE_INPUT));
        outGm.SetGlobalBuffer((__gm__ DTYPE_INPUT*)out, inputSize * sizeof(DTYPE_INPUT));

    }


    __aicore__ inline void Process() {
		for (uint32_t i = 0; i < inputSize; i++) {
			float input = (float)inputGm.GetValue(i);
			if (input == 0)
			{
				auto value = valuesGm.GetValue(i % valueSize);
				outGm.SetValue(i, value);
			} else if (input > 0) {
				outGm.SetValue(i, (DTYPE_INPUT)1);
			} else {
				outGm.SetValue(i, (DTYPE_INPUT)0);
			}
		}
    }

   private:
    TPipe* pipe;
    GlobalTensor<DTYPE_INPUT> inputGm;
    GlobalTensor<DTYPE_INPUT> valuesGm;
    GlobalTensor<DTYPE_INPUT> outGm;

    uint32_t coreIndex, coreNum;
    uint32_t inputSize, valueSize;
    // TBuf<QuePosition::VECCALC> TmpBuf, CntBuf, ABuf, BBuf;
};